package thinkinjava1.ch10;

import java.io.*;

/**
 * Created by BobbyGu on 2017/2/23.
 */
public class IOBug {
    static String baseDir = "src/thinkinjava1.ch10/file_dir/";

    public static void main(String[] args)
            throws Exception {
        DataOutputStream out =
                new DataOutputStream(
                        new BufferedOutputStream(
                                new FileOutputStream(baseDir + "Data.txt")));
        out.writeDouble(3.14159);
        out.writeBytes("That was the value of pi\n");
        out.writeBytes("This is pi/2:\n");
        out.writeDouble(3.14159 / 2);
        out.close();
        DataInputStream in =
                new DataInputStream(
                        new BufferedInputStream(new FileInputStream(baseDir + "Data.txt")));
        BufferedReader inbr =
                new BufferedReader(
                        new InputStreamReader(in));
// The doubles written BEFORE the line of text
// read back correctly:
        System.out.println(in.readDouble());
// Read the lines of text:
        System.out.println(inbr.readLine());
        System.out.println(inbr.readLine());
// Trying to read the doubles after the line
// produces an end-of-file exception:
        System.out.println(in.readDouble());
    }
}
